﻿<%@ Page MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="DiliveryStrategyEdit.aspx.cs" Inherits="RabbitManage.UI.DiliveryStrategyEdit" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    
    <% if (item == null)
       { %>
          什么也没有找到   ╮(╯_╰)╭ 
    <% }
       else
       { %>
    
    <form id="form1" action="../Action/DiliveryStrategyAdd.aspx?id=<%=item.Id %>" method="POST">

        <script type="text/javascript">

            form1.onsubmit = function (e) {
                // stop the regular form submission
                e.preventDefault();

                // collect the form data while iterating over the inputs
                var data = {};
                var provinceList = [];
                for (var i = 0, ii = form1.length; i < ii; ++i) {
                    var input = form1[i];
                    if (input.name) {
                        if (input.name == "selectedProvince") {
                            if (input.checked) {
                                provinceList.push(input.value);
                            }
                        }
                        else {
                            data[input.name] = input.value;
                        }
                    }
                }
                data["ProvinceList"] = provinceList;

                // construct an HTTP request
                var xhr = new XMLHttpRequest();
                xhr.open(form1.method, form1.action, true);
                xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

                // send the collected data as JSON
                xhr.send(JSON.stringify(data));

                xhr.onloadend = function () {
                    // done
                    if (xhr.responseText == "true") {
                        window.location = "/UI/DiliveryStrategyList.aspx";
                    } else {
                        alert(xhr.responseText);
                    }
                };
            };


            function CheckAll() {
                var result = document.getElementById('selectAll').checked;
                var inputs= document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = result;
                }
            }
            
            function CheckReverse() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = !inputs[i].checked;
                }
            }

            var afar = '<%=provinceAfar %>';
            function CheckNear() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];
                    if (afar.indexOf(input.value) == -1) {
                        input.checked = true;
                    } else {
                        input.checked = false;
                    }
                }
            }
        </script>
        <script type="text/javascript" src="../../RabbitShop/Scripts/city.js"></script>
        
        
        规则名称：
        <input type="text" id="inputStrategyName" name="StrategyName" style="width: 400px;" value="<%=item.StrategyName %>" />
        <br/>
        运费：
        <input type="text" id="inputCost" name="Cost" style="width: 40px; text-align: right;" value="<%=item.Cost %>" />
        <br/>
        满包邮：
        <input type="text" id="inputGreaterThan" name="GreaterThan" style="width: 40px; text-align: right;" value="<%=item.GreaterThan %>" />
        <br/>
        省份：
        <input type="checkbox" id="selectAll" onclick="CheckAll();" />全选
        <input type="button" onclick="CheckReverse();" value="反选" />
        <input type="button" onclick="CheckNear();" value="偏远除外" />
        <br/>
    
        <asp:Repeater runat="server" ID="provinceRepeater" >
            <ItemTemplate>
                <input type="checkbox" name="selectedProvince" value="<%#Eval("Name") %>"/><%#Eval("Name") %>
            </ItemTemplate>
        </asp:Repeater>

        <br/>
        <asp:Repeater runat="server" ID="cityRepeater" >
            <ItemTemplate>
                <input type="checkbox" name="selectedCity" value="<%#Container.DataItem %>"/><%#Container.DataItem %>
            </ItemTemplate>
        </asp:Repeater>
        
        <br/>
        <input type="submit" value="保存" />
        
<%--        <script type="text/javascript">
            addressInit('cmbProvince', 'cmbCity', 'cmbArea', '<%=address.Province %>', '<%=address.City %>', '<%=address.Region %>');
        </script>--%>
        
        <script type="text/javascript">

            var provinceJson = '<%=provinceJson %>';
            
            window.onload = function () {

                for (var i = 0, ii = form1.length; i < ii; ++i) {
                    var input = form1[i];
                    if (input.name) {
                        if (input.name == "selectedProvince") {
                            if (provinceJson.indexOf(input.value)!=-1) {
                                input.checked = true;
                            }
                        }
                    }
                }
            };
        </script>

    </form>

  
    <% } %>
    


</asp:Content>